/*
 * Timer.fx
 *
 * Created on 2009-02-27, 12:43:48
 */

package pl.koziolekweb.prezentacja4developers;

import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.scene.CustomNode;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.Text;

/**
 * @author bartlomiejk
 */

public class Timer extends CustomNode {

    public var currentHeight: Float;
    public var currentWidth: Float;
    public var currentTime: Number;
    public var font: Font = Font{
        size: 0
    }

    var watch: Timeline = Timeline{
        repeatCount: Timeline.INDEFINITE
        keyFrames: [
            KeyFrame{
                time: 1s
                action: function():Void{
                    currentTime = currentTime - 1;
                }
            }
        ]
    };

    public function play():Void{
        watch.play();
    }

    public override function create(): Node {
        return Group {
            translateY: bind 0.90 * currentHeight
            content: [
                Rectangle {
                    x: 0,
                    y: 0
                    width: bind currentWidth,
                    height: bind 0.1 * currentHeight,
                    fill: Color.BLACK
                }
                Text {
                    font: bind font
                    x: bind 0.94*currentWidth,
                    y: bind 0.06*currentHeight
                    content: bind "{currentTime}"
                    fill: Color.RED
                }
            ]
        };
    }
}